<template>
    <div>
        <!-- 面包屑导航区 -->
        <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>企业管理</el-breadcrumb-item>
        <el-breadcrumb-item>企业信息列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片视图 -->
        <el-card class="box-card">
            <!-- 搜索与添加区域 -->
        <el-row :gutter="20">
            <el-col :span="8">
                <el-input placeholder="企业名称 /姓名/岗位"  
                class="input-with-select"
                v-model="queryInfo.querystring" clearable
                @clear="getapplylist">
                <el-button slot="append" icon="el-icon-search" @click="getapplylist"></el-button>
                </el-input>
            </el-col>
        </el-row>
        <!-- 应聘信息列表区域 -->
        <el-table
            :data="applylist"
             border stripe>
            <el-table-column
                type="index"
                label="#">
            </el-table-column>
            <el-table-column
                prop="companyname"
                sortable
                label="企业名称">
            </el-table-column>
            <el-table-column
                prop="principal"
                sortable
                label="负责人">
            </el-table-column>
            <el-table-column
                prop="phone"
                sortable
                label="联系电话">
            </el-table-column>
            <el-table-column
                prop="jobs"
                sortable
                label="招聘岗位">
            </el-table-column>
            <el-table-column
                prop="username"
                sortable
                label="用户名">
            </el-table-column>
            <el-table-column
                prop="name"
                sortable
                label="姓名">
            </el-table-column>
            <el-table-column
                prop="mobile"
                sortable
                label="电话">
            </el-table-column>
            <el-table-column
                prop="resume"
                sortable
                label="简历">
                <template slot-scope="scope">
            <a v-if="scope.row.resume" href="javascript:void(0);" @click="download(scope.row.resume)">下载</a>
            <a v-else>未上传简历</a>
          </template>
            </el-table-column>
            <el-table-column
                prop="reviewapply"
                sortable
                label="审核回复">
            </el-table-column>
            <el-table-column
                label="操作" width="180px">
                <template slot-scope="scope">
                    <!-- 删除按钮-->
                    <el-button type="danger" icon="el-icon-delete" size="mini" 
                    @click="removeUserById(scope.row.id)"></el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum"
            :page-sizes="[1, 2, 5, 10]"
            :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>
<script>
export default {
    data(){
        return {
            //获取应聘信息列表的参数
            queryInfo:{
                querystring:'',
                pagenum:1,
                pagesize:2
            },
            applylist:[],
            total:0,
            resumeurl: '', //简历下载链接
            fileName: '', //简历下载路径
            
        }
    },
    created(){
        this.getapplylist()
    },
    methods:{
        async getapplylist(){
        const {data:res} =await this.$http.get('GetAllapply',{params:this.queryInfo})
        if(res.meta.status!=200) return this.$message.error(res.meta.msg)
        this.applylist=res.data.records
        console.log(this.applylist);
        this.total=res.data.total
        },
        //监听pagesize改变的事件
        handleSizeChange(newSize){
            console.log(newSize);
            this.queryInfo.pagesize=newSize
            this.getapplylist()
        },
        //监听页码值改变的数据
        handleCurrentChange(newPage){
            //console.log(newPage);
            this.queryInfo.pagenum=newPage
            this.getapplylist()

        },
        //监听添加应聘信息对话框的关闭事件
        addDialogClosed(){
            this.$refs.addFormRef.resetFields()

        },
        //删除应聘信息
        async removeUserById(id){
          //弹窗
          const confirmResult =await this.$confirm('此操作将永久删除该应聘信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
          }).catch(err=>err)
          //如果应聘信息确定删除则返回字符串 confirm
          //如果应聘信息取消 则cancel
            if(confirmResult!='confirm'){
                return this.$message.info('已经取消删除')
            }
            console.log('确认删除');
            const {data:res}=await this.$http.delete('Deleteapply/'+id)
            if(res.meta.status!=200){
                return this.$message.error('删除应聘信息失败')
            }
            this.$message.success('删除应聘信息成功')
            this.getapplylist()
        },
        //下载
        async download(resume) {
        this.$http({
            // 用axios发送post请求
            method: 'post',
            // 请求地址
            url: 'apply/download?resume=' + resume,
            })
            .then((res) => {
            // 处理返回的文件流
            debugger
            const content = res.data
            const blob = new Blob([content])
            const fileName = resume
            if ('download' in document.createElement('a')) {
                // 非IE下载
                const elink = document.createElement('a')
                elink.download  = fileName
                elink.style.display = 'none'
                elink.href = URL.createObjectURL(blob)
                document.body.appendChild(elink)
                elink.click()
                URL.revokeObjectURL(elink.href) // 释放URL 对象
                document.body.removeChild(elink)
            } else {
                // IE10+下载
                navigator.msSaveBlob(blob, fileName)
            }
            })
        },
        
    }
    
}
</script>

<style lang="less" scoped>

</style>